/*
    UIMessage 模态消息界面
*/

var app = require("app");

cc.Class({
    extends: require("BaseForm"),

    properties: {
        Img: cc.Sprite,
        Tip: cc.Label,
    },

    //初始化
    OnCreateInit: function () {

    },

    //---------显示函数--------------------

    OnShow: function () {
        let self = this;
        let ewm = "http://yanshi.me443.com/touxiang/" + 1 + ".png"

        app.NetManager().SendPack("base.getKefuString", {},
            function (event) {
                //客服判空
                if (!event.KefuString) {
                    self.Tip.string = "暂无联系方式";
                } else {
                    self.Tip.string = "客服微信：" + event.KefuString;
                }
                //二维码
                ewm = event.headUrl;
                let that = self;
                if (ewm) {
                    //加载图片资源
                    app.ControlManager().CreateLoadPromiseByUrl(ewm)
                        .then(function (texture) {
                            if (texture instanceof cc.Texture2D) {
                                if (!cc.isValid(that.Img)) {
                                    return;
                                }
                                let spriteFrame = new cc.SpriteFrame(texture);
                                that.Img.spriteFrame = spriteFrame;
                            }
                            else {
                                that.ErrLog("texture not Texture2D");
                            }
                        })
                        .catch(function (error) {
                            that.ErrLog("OnHttpPack_HeadImagePathInfo error:%s", error.stack);
                        })
                }
            }, function (event) {
                self.Tip.string = "暂无联系方式"

            }
        );
    },
});
